var hash = window.location.hash.slice(1);
var queryTopicId = hash.split(",")[0];
var groupId = hash.split(",")[1];
var queryOrgId = hash.split(",")[2];
var upCode = hash.split(",")[3];
var editCardId = hash.split(",")[4];
var code = 1;
var pageSize = 8;
var queryGroupName ="";
var queryTopicTitle = "";
var shareGroupId="";
var copyCardId = "";
var removeflag ="";//是否移除自身
var delCardId="";//将要删除的cardId;
var currentCardId = "";
var startUrl = "";//视频开头
var temps =[];//视频数组
var copyTitle="";//复制分享修改的标题
var copyFlag = true;//卡片复制/分享标示，true默认为复制
var currentGroupId=groupId;//复制分享移动到的组id
var windowflag =true;
var queryCount = 0;
var pSize =5;
var msgFlag =true;
function uploadShowPostBtn(){
	$("#postShowFile").click();
}
function uploadRePostBtn(){
	$("#rePostFile").click();
}
$(document).ready(function() {
	$(window).scroll(function(){
		var viewH =$(this).height();//可见高度
	    var contentH =$(document).height();//内容高度
	    var scrollTop =$(this).scrollTop();//滚动高度
	    if(scrollTop/(contentH -viewH)>=0.95){ //到达底部100px时,加载新内容
	      // 这里加载数据..
    	  if(windowflag&&pSize<queryCount){
    		  windowflag =false;
    		  pSize+=5;
    		  showTextInfo(currentCardId);
		  }
	    }
	})
	/*复制分享卡片开始*/
	$('#copyModal').on('hidden.bs.modal', function () {
		  $("#copyQueryName").val("");
		  queryGroupName="";
		  pageSize=8;
	});
	$("#msgModal").on('hidden.bs.modal',function(){
		//刷新
		if(msgFlag){
			location.reload();
		}else{
			msgFlag=true;
		}
	})
	$('#copyCardModal').on('hidden.bs.modal', function () {
		  $("#copyCardQueryName").val("");
		  $("#queryTopicName").val("");
		  currentGroupId = groupId;
		  queryGroupName="";
		  queryTopicTitle = "";
		  copyCardId="";
		  removeflag="";
		  pageSize=8;
		  copyFlag = true;
		  $('#copyCardModal').find(".copy-card").show();
		  $('#copyCardModal').find(".move-card").hide();
	});
	$("#queryTopicName").keyup(function(){
		queryTopicTitle = $(this).val();
		cardTopicList(currentGroupId,removeflag);
	})
	/*复制分享卡片结束*/
	//跳转到群组list
	$(".logo-img").click(function(){
		window.location.href="../meetingList/meetingList.html#"+queryOrgId;
	});
	cardList();
	findTopic();
	$(".orderList").click(function() {
		code = 1;
		cardList();
	});
	$(".newList").click(function() {
		code = 2;
		cardList();
	});
	$(".dianzan").click(function() {
		this.src = "../../skin/img/sticonright11.png";
		$(".st-zan").show();
	});
	$("#st-liuyanicon").click(function() {
		$("html, body").animate({
			scrollTop: $("#pingLun").offset().top-100
		}, {
			duration: 500,
			easing: "swing"
		});
		return false;
	});
	//查询视频路径配置
	$.ajax({
		url:"../../../learn/card/findFlashStart.json",
		success:function(data){
			startUrl = data.data;
		}
	});
	//主题信息
	function findTopic(){
		$.get('../../../hivelearn/topic/findTopic.json?id=' + queryTopicId+'&groupId='+groupId+'&view=1', function(datas) {
			if (datas.success) {
				if(datas.data.cardNum==0){
					$(".empty-list").removeClass("no-show");
					$(".content-card-list").addClass("no-show");
				}else{
					$(".empty-list").addClass("no-show");
					$(".content-card-list").removeClass("no-show");
				}
				var dom = _.template($('#topicTpl').html());
				dom = dom(datas.data);
				$("#topic").html(dom);
			}
		})
	}
	//列表查询
	function cardList() {
		$.get('../../../hivelearn/card/findCardList.json?queryTopicId=' + queryTopicId+'&groupId='+groupId+'&code='+code, function(datas) {
			if (datas.success) {
				for(var i = 0;i<datas.data.resultList.length;i++){
					var d = datas.data.resultList[i];
					if(d.cardTitle.length>20){
						d.cTitle = d.cardTitle.substring(0,20)+"...";
					}else{
						d.cTitle = d.cardTitle;
					}
				}
				var dom = _.template($('#cardListTpl').html());
				datas.data.groupId = groupId;
				datas.data.topicId = queryTopicId;
				datas.data.orgId = queryOrgId;
				dom = dom(datas.data);
				$("#cardList").html(dom);
				//默认加载
				if(datas.data.resultList.length>0){
					if(editCardId){
						cardView(editCardId);
					}else{
						cardView(datas.data.resultList[0].cardId);
					}
				}
				isShow();
			}
		})
	}
});

function toTopicList(){
	if(upCode && upCode != null && upCode == 1){
		window.location.href="../activityInfo/activityInfo.html#"+groupId+","+queryOrgId;
	}else{
		window.location.href="../meetingtheme/meetingTheme.html#"+groupId+","+queryOrgId;
	}
}
//内容
function showTextInfo(id){
	$.get('../../../hivelearn/cardtext/findCardTextList.json?queryCardId=' + id+'&groupId='+groupId+'&pageSize='+pSize, function(datas) {
		 windowflag =true;
		if (datas.success) {
			queryCount=datas.data.count;
			$("#editCard").attr("href","../studyTalkEdit/studyTalkEdit.html#"+id+","+groupId+","+queryTopicId+","+queryOrgId);
			var dom = _.template($('#contentBoxTpl').html());
			datas.data.startUrl = startUrl;
			dom = dom(datas.data);
			$("#contentBox").html(dom);
			for(var i =0;i<datas.data.resultList.length;i++){
				var d = datas.data.resultList[i];
				if(d.playUrl){
					if(temps.indexOf(d.cardTextId)==-1){
						videojs("my-video-"+d.cardTextId);
						temps.push(d.cardTextId);
					}else{
						videojs("my-video-"+d.cardTextId).dispose();
						videojs("my-video-"+d.cardTextId);
					}
				}
			}
			initSlide();
		}
	})
}
function editOneCard(){
	window.location.href="../studyTalkEdit/studyTalkEdit.html#"+currentCardId+","+groupId+","+queryTopicId+","+queryOrgId;
}
//关键点
function showKeyPoint(id){
	$.get('../../../learn/keypoint/findKeyPointList.json?queryCardId=' + id+'&groupId='+groupId, function(datas) {
		if (datas.success) {
			$(".st-gjdnum").text(datas.data.resultList.length);
//			var dom = _.template($('#contentBoxTpl').html());
//			dom = dom(datas.data);
//			$("#contentBox").html(dom);
		}
	})
}
//回复
function showReply(id){
	$.get('../../../hivelearn/hivelearnactivity/findHiveLearnActivity.json?id=' + id+'&groupId='+groupId, function(datas) {
		if (datas.success) {
			var text = "评论（"+datas.data.dtoList.length+"）";
			$(".st-plnum").text(text);
			var dom = _.template($('#replyShowTpl').html());
			dom = dom(datas.data);
			$("#replyShow").html(dom);
			
			$(".postHuiFu").each(function(){
				$(this).hide();
//				$(this).click()
			});
			isShow();
		}
	})
}
var isPraise;
function dianZan(){
	var code;
	if(isPraise==1){
		code=2;
	}else{
		code=1;
	}
	$.get('../../../hivelearn/praise/addOrDelPraise.json?objectId=' + currentCardId+'&objectType=1&code='+code+'&groupId='+groupId, function(datas) {
		if (datas.success) {
			cardView(currentCardId);
		}
	})
	
}
//点赞
function fabulous(id,type,code,page,cardId){
	$.get('../../../hivelearn/praise/addOrDelPraise.json?objectId=' + id+'&objectType='+type+'&code='+code+'&groupId='+groupId, function(datas) {
		if (datas.success) {
			cardView(cardId);
		}
	})
}
function deletePost(id,code){
	$.get('../../../hivelearn/hivelearnpost/deleteReplyPostByIds.json?ids=' + id+'&groupId='+groupId+'&code='+code+'&cardId='+currentCardId, function(datas) {
		if (datas.success) {
			cardView(currentCardId);
		}
	})
}
function cardView(id){
	currentCardId = id;
	$.get('../../../hivelearn/card/findCard.json?id=' + id+'&groupId='+groupId, function(datas) {
		if (datas.success) {
			$(".st-title").text(datas.data.cardTitle);
			$(".st-author").text(datas.data.userName);
			$(".st-time").text(datas.data.createDateStr);
			$(".cardDzNum").text(datas.data.numVisits);
			$(".cardFwNum").text(datas.data.numReply);
			$(".st-zan1").text(datas.data.numPraise);
			isPraise = datas.data.isPraise;
			if(isPraise==1){
				$(".dianzan").attr("src","../../skin/img/sticonright11.png");
			}else{
				$(".dianzan").attr("src","../../skin/img/sticonright1.png");
			}
			var dom = _.template($('#pingLunTpl').html());
			dom = dom(datas.data);
			$("#pingLun").html(dom);
			//加载内容
			showTextInfo(id);
//			showKeyPoint(id);
			showReply(id);
		}
	})
}
function submitRePost(id,code,activeId){
	var postContent = $("#rePostInput"+id).val();
	var attachId = $("#RePostCover").val();
	if(postContent==null||postContent==""){
		$("#msgModal").find(".msg").text("回复内容不能为空！");
		$("#msgModal").modal("show");
		msgFlag=false;
		return false;
	}
	if(postContent.length>=100){
		$("#msgModal").find(".msg").text("回复内容不得超过100个字！");
		$("#msgModal").modal("show");
		msgFlag=false;
		return false;
	}
	var pattern = new RegExp("[`@#$^&*]");
	if(pattern.test(postContent)){
		$("#msgModal").find(".msg").text("回复内容不能包含特殊字符！");
		$("#msgModal").modal("show");
		msgFlag=false;
	    return false;
	}
	$.get(encodeURI('../../../hivelearn/hivelearnpost/replyPost.json?parentId=' + id+'&attachId='+attachId+'&postContent='+postContent+'&code='+code+'&groupId='+groupId), function(datas) {
		if (datas.success) {
			cardView(activeId);
		}
	})
}
function submitPostReply(id,code){
	var postContent = $("#st-postLiuyan").val();
	var attachId = $("#postShowCover").val();
	if(postContent==null||postContent==""){
		$("#msgModal").find(".msg").text("回复内容不能为空！");
		$("#msgModal").modal("show");
		msgFlag=false;
		return false;
	}
	if(postContent.length>=100){
		$("#msgModal").find(".msg").text("回复内容不得超过100个字！");
		$("#msgModal").modal("show");
		msgFlag=false;
		return false;
	}
	var pattern = new RegExp("[`@#$^&*]");
	if(pattern.test(postContent)){
		$("#msgModal").find(".msg").text("回复内容不能包含特殊字符！");
		$("#msgModal").modal("show");
		msgFlag=false;
	    return false;
	}
	$.get(encodeURI('../../../hivelearn/hivelearnpost/replyPost.json?parentId=' + id+'&attachId='+attachId+'&postContent='+postContent+'&code='+code+'&groupId='+groupId), function(datas) {
		if (datas.success) {
			cardView(id);
		}
	})
}
var cpId;
function zhanKai(id){
	$("."+id).show();
	cpId = id;
}

/*********卡片编辑**********/
//修改主题
function editTopic(){
	window.location.href="../meetingtheme/meetingThemeEdit.html#"+queryTopicId+","+groupId+","+queryOrgId+","+2;
}
//新增卡片
function addCard(){
	$.ajax({
		url:"../../../hivelearn/card/saveCard.json",
		data:{"groupId":groupId,"topicId":queryTopicId,"cardTitle":"未定义"},
		success:function(data){
			window.location.href="../studyTalkEdit/studyTalkEdit.html#"+data.data.cardId+","+groupId+","+queryTopicId+","+queryOrgId+",1";
		}
	})
}

//群组列表查询
function groupList(groupId,noGroupId) {
	$.get('../../../hivelearn/group/findCopyGroupList.json?queryOrgId='+queryOrgId+"&pageSize="+pageSize
			+"&queryGroupName="+queryGroupName+"&queryGroupId="+groupId+"&queryNoGroupId="+noGroupId, function(datas) {
		if (datas.success) {
			var dom;
			if(groupId){
				//复制
				dom = _.template($('#groupTpl').html());
			}else{
				//分享
				dom = _.template($('#shareGroupTpl').html());
			}
			
			var count = datas.data.count;
			dom = dom(datas.data);
			$("#grouplist").html(dom);
			//滚动加载
			$("#copyModal").find(".right-list").scroll(function () {  
                var $this = $(this),  
                viewH = $(this).height(),//可见高度  
                contentH = $(this).get(0).scrollHeight,//内容高度  
                scrollTop = $(this).scrollTop();//滚动高度  
                //if(contentH - viewH - scrollTop <= 100) { //到达底部100px时,加载新内容  
                if (scrollTop / (contentH - viewH) >= 0.98&&count>pageSize) { //到达底部100px时,加载新内容  
                    //console.log("scrollTop："+scrollTop+",contentH："+contentH+",viewH："+viewH);  
                    pageSize+=5;
                    groupList(groupId,noGroupId);
                }  
            }); 
		}
	})
}
//群组列表查询（card）
function cardGroupList(groupId,noGroupId) {
	$.get('../../../hivelearn/group/findCopyGroupList.json?queryOrgId='+queryOrgId+"&pageSize="+pageSize
			+"&queryGroupName="+queryGroupName+"&queryGroupId="+groupId+"&queryNoGroupId="+noGroupId, function(datas) {
		if (datas.success) {
			var dom;
			dom = _.template($('#shareCardGroupTpl').html());
			
			var count = datas.data.count;
			dom = dom(datas.data);
			$("#cardGrouplist").html(dom);
			//滚动加载
			$("#copyCardModal").find(".right-content-list").find(".right-list").scroll(function () {  
                var $this = $(this),  
                viewH = $(this).height(),//可见高度  
                contentH = $(this).get(0).scrollHeight,//内容高度  
                scrollTop = $(this).scrollTop();//滚动高度  
                //if(contentH - viewH - scrollTop <= 100) { //到达底部100px时,加载新内容  
                if (scrollTop / (contentH - viewH) >= 0.98&&count>pageSize) { //到达底部100px时,加载新内容  
                    //console.log("scrollTop："+scrollTop+",contentH："+contentH+",viewH："+viewH);  
                    pageSize+=5;
                    cardGroupList(groupId,noGroupId);
                }  
            }); 
		}
	})
}
//群组列表查询（card）
function cardTopicList(id,flag) {
	currentGroupId=id;
	pageSize=8;
	removeflag = flag;
	$.get("../../../hivelearn/topic/findTopicList.json?pageSize="+pageSize
			+"&queryTopicTitle="+queryTopicTitle+"&queryGroupId="+id+"&groupId="+id, function(datas) {
		if (datas.success) {
			var dom;
			dom = _.template($('#cardGroupTpl').html());
			
			if(flag){
				datas.data.topicQuery.moveflag = 1;
				for(var i=0;i<datas.data.topicQuery.resultList.length;i++){
					if(queryTopicId==datas.data.topicQuery.resultList[i].topicId){
						datas.data.topicQuery.resultList[i].flag = 1;//用于移动card时，不能移动到自己下
					}
				}
			}else{
				datas.data.topicQuery.moveflag=0;
			}
			var count = datas.data.topicQuery.count;
			dom = dom(datas.data.topicQuery);
			$("#cardTopicList").html(dom);
			$("#copyCardModal").find(".right-content-list").hide();
			$("#copyCardModal").find(".right-content-edit").show();
			//返回
			$("#copyCardModal").find(".share-btn").find(".arrow").click(function(){
				$("#copyCardModal").find(".right-content-list").show();
				$("#copyCardModal").find(".right-content-edit").hide();
				$("#queryTopicName").val("");
				queryTopicTitle="";
			});
			//滚动加载
			$("#copyCardModal").find(".right-content-edit").find(".right-list").scroll(function () {  
				var $this = $(this),  
				viewH = $(this).height(),//可见高度  
				contentH = $(this).get(0).scrollHeight,//内容高度  
				scrollTop = $(this).scrollTop();//滚动高度  
				//if(contentH - viewH - scrollTop <= 100) { //到达底部100px时,加载新内容  
				if (scrollTop / (contentH - viewH) >= 0.98&&count>pageSize) { //到达底部100px时,加载新内容  
					//console.log("scrollTop："+scrollTop+",contentH："+contentH+",viewH："+viewH);  
					pageSize+=5;
					cardGroupList(id);
				}  
			}); 
		}
	})
}
//保存复制card
function saveCopyCard(id){
	var url ="";
	if(copyFlag){
		url = "../../../hivelearn/card/copyCard.json";
	}else{
		url = "../../../hivelearn/card/shareCard.json";
	}
	$.ajax({
		url:url,
		data:{"cardId":copyCardId,"topicId":id,"groupId":groupId,"cardTitle":copyTitle},
		success:function(data){
			$("#copyCardModal").modal("hide");
			$("#msgModal").find(".msg").text("保存成功");
			$("#msgModal").modal("show");
		}
	})
}
//删除
function deleteTopic(){
	$('#delModal').modal('show');
}
//复制
function copyTopic(){
	$("#copyModal").find(".right-content-list").show();
	$("#copyModal").find(".right-content-edit").hide();
	$("#copyModal").find(".topicImg").empty();
	$("#copyModal").find(".topicTitle").text("");
	$("#copyModal").find(".topicTitle").attr("title","");
	$("#copyModal").find(".title").text("复制");
	$("#copyModal").find(".right-top").text("你想复制到哪里？");
	$.ajax({
		url:'../../../hivelearn/topic/findTopic.json?id=' + queryTopicId
		+ '&groupId=' + groupId,
		success:function(data){
			if(data.data.topicCover){
				var topicImg = "<img src='../../../components/gtattachment/open/downloadAttachment.json?attachmentId="+data.data.topicCover+"'/>"
				$("#copyModal").find(".topicImg").append(topicImg);
			}
			copyTitle = data.data.topicTitle;
			$("#copyModal").find(".topicTitle").text(data.data.topicTitle);
			$("#copyModal").find(".topicTitle").attr("title",data.data.topicTitle);
			groupList(groupId,"");
			$("#copyQueryName").unbind("keyup");
			$("#copyQueryName").keyup(function(){
				queryGroupName = $(this).val();
				groupList(groupId,"");
			})
			$('#copyModal').modal('show');
		}
	})
}
//复制card
function copyCard(id){
	copyCardId = id;
	$("#copyCardModal").find(".right-content-list").show();
	$("#copyCardModal").find(".right-content-edit").hide();
	$("#copyCardModal").find(".topicImg").empty();
	$("#copyCardModal").find(".topicTitle").text("");
	$("#copyCardModal").find(".topicTitle").attr("title","");
	$("#copyCardModal").find(".title").text("复制");
	$("#copyCardModal").find(".right-top").text("你想复制到哪里？");
	$.ajax({
		url:'../../../hivelearn/card/findCard.json?id=' + id
		+ '&groupId=' + groupId,
		success:function(data){
			if(data.data.cardCover){
				var cardCover = "<img src='../../../components/gtattachment/open/downloadAttachment.json?attachmentId="+data.data.cardCover+"'/>"
				$("#copyCardModal").find(".topicImg").append(cardCover);
			}
			copyTitle=data.data.cardTitle;
			$("#copyCardModal").find(".topicTitle").text(data.data.cardTitle);
			$("#copyCardModal").find(".topicTitle").attr("title",data.data.cardTitle);
			cardGroupList(groupId,"");
			$("#copyCardQueryName").unbind("keyup");
			$("#copyCardQueryName").keyup(function(){
				queryGroupName = $(this).val();
				cardGroupList(groupId,"");
			})
			$('#copyCardModal').modal('show');
		}
	})
}
function copyOneCard(){
	copyCard(currentCardId);
}
//分享card
function shareCard(id){
	copyFlag = false;
	copyCardId = id;
	$("#copyCardModal").find(".right-content-list").show();
	$("#copyCardModal").find(".right-content-edit").hide();
	$("#copyCardModal").find(".topicImg").empty();
	$("#copyCardModal").find(".topicTitle").text("");
	$("#copyCardModal").find(".topicTitle").attr("title","");
	$("#copyCardModal").find(".title").text("分享");
	$("#copyCardModal").find(".right-top").text("你想分享到哪里？");
	$.ajax({
		url:'../../../hivelearn/card/findCard.json?id=' + id
		+ '&groupId=' + groupId,
		success:function(data){
			if(data.data.cardCover){
				var cardCover = "<img src='../../../components/gtattachment/open/downloadAttachment.json?attachmentId="+data.data.cardCover+"'/>"
				$("#copyCardModal").find(".topicImg").append(cardCover);
			}
			copyTitle=data.data.cardTitle;
			$("#copyCardModal").find(".topicTitle").text(data.data.cardTitle);
			$("#copyCardModal").find(".topicTitle").attr("title",data.data.cardTitle);
			cardGroupList("",groupId);
			$("#copyCardQueryName").unbind("keyup");
			$("#copyCardQueryName").keyup(function(){
				queryGroupName = $(this).val();
				cardGroupList("",groupId);
			})
			$('#copyCardModal').modal('show');
		}
	})
}
function shareOneCard(){
	shareCard(currentCardId);
}
//移动card
function moveCard(id){
	  $('#copyCardModal').find(".copy-card").hide();
	  $('#copyCardModal').find(".move-card").show();
	copyCardId = id;
	$("#copyCardModal").find(".right-content-edit").show();
	$("#copyCardModal").find(".right-content-list").hide();
	$("#copyCardModal").find(".topicImg").empty();
	$("#copyCardModal").find(".topicTitle").text("");
	$("#copyCardModal").find(".topicTitle").attr("title","");
	$("#copyCardModal").find(".title").text("移动");
	$("#copyCardModal").find(".right-top").text("你想移动到哪里？");
	$.ajax({
		url:'../../../hivelearn/card/findCard.json?id=' + id
		+ '&groupId=' + groupId,
		success:function(data){
			if(data.data.cardCover){
				var cardCover = "<img src='../../../components/gtattachment/open/downloadAttachment.json?attachmentId="+data.data.cardCover+"'/>"
				$("#copyCardModal").find(".topicImg").append(cardCover);
			}
			copyTitle = data.data.cardTitle;
			$("#copyCardModal").find(".topicTitle").text(data.data.cardTitle);
			$("#copyCardModal").find(".topicTitle").attr("title",data.data.cardTitle);
			cardTopicList(currentGroupId,1);
			$("#queryTopicName").unbind("keyup");
			 $("#queryTopicName").keyup(function(){
				 queryTopicTitle = $(this).val();
				cardTopicList(currentGroupId,1);
			})
			$('#copyCardModal').modal('show');
		}
	})
}
function moveOneCard(){
	moveCard(currentCardId);
}
//保存复制card
function saveMoveCard(id){
	$.ajax({
		url:"../../../hivelearn/card/moveCard.json",
		data:{"cardId":copyCardId,"topicId":id,"groupId":groupId,"cardTitle":copyTitle},
		success:function(data){
			$("#copyCardModal").modal("hide");
			$("#msgModal").find(".msg").text("移动成功");
			$("#msgModal").modal("show");
		}
	})
}
//分享
function shareTopic(){
	$("#copyModal").find(".right-content-list").show();
	$("#copyModal").find(".right-content-edit").hide();
	$("#copyModal").find(".topicImg").empty();
	$("#copyModal").find(".topicTitle").text("");
	$("#copyModal").find(".topicTitle").attr("title","");
	$("#copyModal").find(".title").text("分享");
	$("#copyModal").find(".right-top").text("你想分享到哪里？");
	$.ajax({
		url:'../../../hivelearn/topic/findTopic.json?id=' + queryTopicId
		+ '&groupId=' + groupId,
		success:function(data){
			if(data.data.topicCover){
				var topicImg = "<img src='../../../components/gtattachment/open/downloadAttachment.json?attachmentId="+data.data.topicCover+"'/>"
				$("#copyModal").find(".topicImg").append(topicImg);
			}
			$("#copyModal").find(".topicTitle").text(data.data.topicTitle);
			$("#copyModal").find(".topicTitle").attr("title",data.data.topicTitle);
			groupList("",groupId);
			$("#copyQueryName").unbind("keyup");
			$("#copyQueryName").keyup(function(){
				queryGroupName = $(this).val();
				groupList("",groupId);
			})
			$('#copyModal').modal('show');
		}
	})
}
function delTopic(){
	$.ajax({
		url:"../../../hivelearn/topic/deleteTopicById.json?id="+queryTopicId+"&groupId="+groupId,
		success:function(data){
			$('#delModal').modal('hide');
			topicList();
		},
		error:function(data){
			$('#delModal').modal('hide');
			topicList();
		}
	})
}
function topicList(){
	window.location.href="../meetingtheme/meetingTheme.html#"+groupId+","+queryOrgId;
}
function saveCopyTopic(id){
	$.ajax({
		url:"../../../hivelearn/topic/copyTopic.json",
		data:{"groupId":id,"topicId":queryTopicId,"topicTitle":copyTitle},
		success:function(data){
			$('#copyModal').modal('hide');
			topicList();
		}
	});
}
//显示分享修改页面
function shareTopicInfo(id,groupName){
	shareGroupId = id;
	var title = $("#copyModal").find(".topicTitle").text();
	$("#copyModal").find(".right-content-list").hide();
	$("#copyModal").find(".right-content-edit").show();
	$("#updateTopicTitle").val(title);
	$("#copyModal").find(".right-top").text("分享到："+groupName);
	$("#copyModal").find(".right-top").attr("title","分享到："+groupName);
	//返回
	$("#copyModal").find(".share-btn").find(".arrow").click(function(){
		$("#copyModal").find(".right-content-list").show();
		$("#copyModal").find(".right-content-edit").hide();
		$("#updateTopicTitle").val("");
		$("#copyModal").find(".right-top").text("你想分享到哪里？");
		$("#copyModal").find(".right-top").attr("title","");
		$("#copyModal").find(".error-msg").text("");
	});
	$("#copyModal").find("#updateTopicTitle").unbind("keyup");
	$("#copyModal").find("#updateTopicTitle").keyup(function(){
		if($(this).val()){
			$("#copyModal").find(".error-msg").text("");
		}
	});
}
//保存分享
function saveShareTopic(id){
	$.ajax({
		url:"../../../hivelearn/topic/shareTopic.json",
		data:{"groupId":id,"topicId":queryTopicId,"topicTitle":copyTitle},
		success:function(data){
			$('#copyModal').modal('hide');
			topicList();
		}
	});
}
function deleteCard(id){
	delCardId=id;
	$('#delCardModal').modal('show');
}
function showUserView(id){
	$.get('../../../hivelearn/topic/findTopicViewList.json?queryTopicId='+id+"&groupId="+groupId, function(datas) {
		if (datas.success) {
			var dom;
			dom = _.template($('#userViewTpl').html());
			dom = dom(datas.data);
			$("#userView").html(dom);
		}
		$('#userViewModal').modal('show');
	})
}
function deleteOneCard(){
	deleteCard(currentCardId);
}
function delCard(){
	$.ajax({
		url:"../../../hivelearn/card/deleteCardByIds.json",
		data:{"id":delCardId,"groupId":groupId},
		success:function(data){
			if(data.success){
				$("#delCardModal").modal("hide");
				$("#msgModal").find(".msg").text("删除成功");
				$("#msgModal").modal("show");
			}
		}
	})
}
//上传附件
function uploadRePostShowFile() {
	/*$.ajax({
		url : "../../../hivelearn/topic/uploadFileImage.json",
		data : new FormData($('#uploadRePostForm')[0]),
		method : "post",
		processData : false,
		contentType : false,
		cache : false,
		success : function(data){ // 服务器成功响应处理函数
			$('[name="RePostCover"]').val(data.data.attachid);
			console.log("上传成功");
			$("#rePostFile").val("");
			
		},
		error : function(data){// 服务器响应失败处理函数
			console.log("服务器异常");
			$("#rePostFile").val("");
		}
	});*/
	$("#uploadRePostForm").ajaxSubmit({
    	url: "../../../hivelearn/topic/uploadFileImage.json?_t="+new Date().getTime(),
        data:$("#uploadRePostForm").serialize(),
        dataType:"json",
        success:function(data){
        	$('[name="RePostCover"]').val(data.attachid);
			console.log("上传成功");
			
			$("#picShowRePostView"+cpId).show();
			var type = data.attachextname;
			if(type=="jpg"||type=="gif"||type=="png"||type=="jpeg"){
				var img = "<img style=\"width: 515px;margin-left: -20px;\" src=\"../../../components/gtattachment/open/downloadAttachment.json?attachmentId="
					+ data.attachid+"\"/>";
				$("#picShowRePostView"+cpId).empty();
				$("#picShowRePostView"+cpId).append(img);
			}else if(type=="doc"||type=="docx"||type=="xls"||type=="xlsx"||type=="pdf"){
//				var img ="<div class=\"st-docbox\" style=\"height: 40px;\">"+
//					"<div class=\"row st-docp\"style=\"width: 250px;margin-left: -20px;height: 81px;\">"+
//					"<div class=\"col-md-4 st-docp1\" style=\"height: 80px;width: 80px;\">"+
//					"</div>"+
//					"<div class=\"col-md-7 st-docp2\" style=\"width: 165px;\">"+
//					data.attachname+
//					"</div>"+
//					"</div>";
				$("#picShowRePostView"+cpId).empty();
//				$("#picShowRePostView"+cpId).append(img);
				$('#uploadReShowPostView'+cpId).html(type + "附件 上传成功");
			}
			$("#shangChuanC").css("pointer-events","none");
			$("#shangChuanC").css("cursor","default");
			
			$("#rePostFile").val("");
		},
		error:function(data){
			console.log("服务器异常");
			$("#rePostFile").val("");
		}
    });
}
///上传附件
function uploadPostShowFile() {
	/*if ($("#postShowFile").val()&&checkfile(e)) {
		$.ajax({
			url : "../../../hivelearn/topic/uploadFileImage.json",
			data : new FormData($('#uploadPostShowForm')[0]),
			method : "post",
			processData : false,
			contentType : false,
			cache : false,
			success : function(data){ // 服务器成功响应处理函数
				$('[name="postShowCover"]').val(data.data.attachid);
				console.log("上传成功");
				$("#postShowFile").val("");
				
			},
			error : function(data){// 服务器响应失败处理函数
				console.log("服务器异常");
				$("#postShowFile").val("");
			}
		});
	}
	return false;*/
	$("#uploadPostShowForm").ajaxSubmit({
    	url: "../../../hivelearn/topic/uploadFileImage.json?_t="+new Date().getTime(),
        data:$("#uploadPostShowForm").serialize(),
        dataType:"json",
        success:function(data){
			$('[name="postShowCover"]').val(data.attachid);
			console.log("上传成功");

			$("#picShowPostView").show();
			var type = data.attachextname;
			if(type=="jpg"||type=="gif"||type=="png"||type=="jpeg"){
				var img = "<img style=\"width:720px;margin-left: -5px;\" src=\"../../../components/gtattachment/open/downloadAttachment.json?attachmentId="
					+ data.attachid+"\"/>";
				$('#picShowPostView').empty();
				$("#picShowPostView").append(img);
			}else if(type=="doc"||type=="docx"||type=="xls"||type=="xlsx"||type=="pdf"){
//				var img ="<div class=\"st-docbox\" style=\"\">"+
//					"<div class=\"row st-docp\"style=\"width: 384px;margin-left: -5px !important;\">"+
//					"<div class=\"col-md-2\">"+
//					"<img src=\"../../skin/img/Word.png\" style=\"width: 50px;height: 50px;margin-top: 10px;\">"+
//					"</div>"+
//					"<div class=\"col-md-7 st-docp2\">"+
//					data.attachname+
//					"</div>"+
//					"</div>";
				$('#picShowPostView').empty();
//				$("#picShowPostView").append(img);
				$('#uploadShowPostView').html(type + "附件 上传成功");
			}
			$("#shangChuanC").css("pointer-events","none");
			$("#shangChuanC").css("cursor","default");
			
			$("#postShowFile").val("");
		},
		error:function(data){
			console.log("服务器异常");
			$("#postShowFile").val("");
		}
    });
}

//检查
/*function checkfileRePost(target) {
	var isIE = /msie/i.test(navigator.userAgent) && !window.opera; 
	var fileSize = 0;
	var filetypes = [ ".jpg", ".png", ".gif", ".doc", ".docx", ".xls", ".xlsx", ".mp3", ".mp4"];
	var filepath = target.value;
	var filemaxsize = 1024 * 20;// 20M
	if (filepath) {
		var isnext = false;
		var fileend = filepath.substring(filepath.indexOf("."));
		if (filetypes && filetypes.length > 0) {
			for ( var i = 0; i < filetypes.length; i++) {
				if (filetypes[i] == fileend) {
					isnext = true;
					break;
				}
			}
		}
		if (!isnext) {
			$("#msgModal").find(".msg").text("请选择.png，.jpg，.gif，.doc，.docx，.xls，.xlsx，.mp3，.mp4文件上传");
			$("#msgModal").modal("show");
			target.value = "";
			return false;
		}
	} else {
		return false;
	}
	if (isIE && !target.files) {
		ieUpload(target, "rePostFile", uploadPostShowFile, filemaxsize);
	} else {
		fileSize = target.files[0].size;
		var size = fileSize / 1024;
		if (size > filemaxsize) {
			$("#msgModal").find(".msg").text("文件大小不能大于" + filemaxsize / 1024 + "M！");
			$("#msgModal").modal("show");
			target.value = "";
			return false;
		}
		if (size <= 0) {
			$("#msgModal").find(".msg").text("文件大小不能为0M！");
			$("#msgModal").modal("show");
			target.value = "";
			return false;
		}
	}
}*/
function downloadFile(id){
	window.location.href="../../../components/gtattachment/open/downloadAttachment.do?attachmentId="+id;
}

var word_w = "600px";
var word_h = "830px";
var ppt_w = "600px";
var ppt_h = "370px";
function initSlide(){
	 $(".ck-slide").each(function(){
		if(!$(this).hasClass("ppt")){
				$(this).css("width",word_w);
				$(this).find("img").css("width",word_w);
				$(this).ckSlide({
					dir: 'x'
				});
	           $(this).find(".ck-slide-dir").css("height",word_h);
	           $(this).find(".ck-slide-dir").css("width",word_w);
           }else{
        	   $(this).css("width",ppt_w);
        	   $(this).find("img").css("width",ppt_w);
        	   $(this).ckSlide({
					dir: 'x'
				});
	           $(this).find(".ck-slide-dir").css("height",ppt_h);
	           $(this).find(".ck-slide-dir").css("width",ppt_w);
           }
		});
}
//修改复制，分享标题
function toUpdateTitle(e){
	$(e).hide();
	var $title = $(e).siblings(".topicTitle");
	var title= $title.text();
	$title.empty();
	$title.append("<input type='text' class='updateCopyTitle' maxlength='40' value='"+title+"'/>");
	$title.find(".updateCopyTitle").focus();
	$title.find(".updateCopyTitle").blur(function(){
		var $val = $(this).val();
		if($val&&$.trim($val)){
			copyTitle=$val;
		}
		$title.empty();
		$title.text(copyTitle);
		$(e).show();
	})
}
